package com.itheima.test5;

import java.util.Scanner;

public class carTest {
    public static void main(String[] args) {
        //1.创建数组，存放3个汽车对象
        car[] arr = new car[3];

        //2.创建汽车对象，数据来自于键盘录入
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < arr.length; i++) {
            //创建汽车的对象
            car c = new car();//每次循环都要创建一个对象
            //录入品牌
            System.out.println("请输入第" + (i + 1) + "个汽车的品牌");
            String brand = sc.next();
            c.setBrand(brand);

            //录入价格
            System.out.println("请输入第" + (i + 1) + "个汽车的价格");
            int prize = sc.nextInt();
            c.setPrize(prize);

            //录入颜色
            System.out.println("请输入第" + (i + 1) + "个汽车的颜色");
            String model = sc.next();
            c.setColor(model);

            //把汽车对象添加到数组中
            arr[i] = c;
        }

        //3.遍历数组
        for (int i = 0; i < arr.length; i++) {
            car car = arr[i];
            System.out.println(car.getBrand() + "," + car.getPrize() + "," + car.getColor());
        }
    }
}
